﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using MyHotel_DTO;
using MyHotel_Common;
using DTO;
using System.Data.SqlClient;

namespace MyHotel_DAO
{
    public class ChucVuDAO : DAO
    {
        protected override object createObjectFromDatarow(DataRow row)
        {
          ChucVu   cv = new ChucVu();
            cv.Machucvu = int.Parse(row["MaChucVu"].ToString());
            cv.Tenchucvu = row["TenChucVu"].ToString();
            return cv;
        }
         
        public List<ChucVu> getList()
        {

            string name_proc = "USP_LAY_DANH_SACH_ChucVu";
            DataTable dt = DataProvider.executeStoreProcedureQuery(name_proc, null);
            return getListFromDataTable<ChucVu>(dt);
        }

        public bool themChucVu(ChucVu cv)
        {
            
            string nameProc = "SP_THEMCHUCVU";
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@TenChucVu",cv.Tenchucvu);
           

            return (DataProvider.executeStoreProcedureNonQuery(nameProc, para) == 1);
            
        }

        public List<ChucVu> getListChucVuByMaNV(int maNhanVien)
        {

            string name_proc = "SP_GETLISTCHUCVU_BY_MANV";
            DataTable dt = DataProvider.executeStoreProcedureQuery(name_proc, new SqlParameter("@MANV", maNhanVien));
            return getListFromDataTable<ChucVu>(dt);
        }

        public List<ChucVu> getListChucVuKhongDamNhiemByMaNV(int maNhanVien)
        {

            string name_proc = "SP_GETLISTCHUCVU_KHONG_DAM_NHIEM_BY_MANV";
            DataTable dt = DataProvider.executeStoreProcedureQuery(name_proc, new SqlParameter("@MANV", maNhanVien));
            return getListFromDataTable<ChucVu>(dt);
        }
    }
}
